<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <!--
    Common files don't take part in the root src\tests\Directory.Build.targets
    This file prevents them from including it as it gets included in its place
    If they ever need to take part, we can conditionally include them as documented
    here https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build#directorybuildprops-and-directorybuildtargets
  -->
  <Import Project="$(MSBuildThisFileDirectory)/Common/disableversioncheck.targets"
          Condition="'$(DisableVersionCheckImported)' != 'true'" />

  <PropertyGroup Condition="'$(TargetsAppleMobile)' == 'true' and '$(RuntimeFlavor)' == 'mono'">
    <OSPlatformConfig>$(TargetOS).AnyCPU.$(Configuration)</OSPlatformConfig>
    <TestArchiveRoot>$(ArtifactsDir)helix/</TestArchiveRoot>
    <TestArchiveTestsRoot>$(TestArchiveRoot)tests/</TestArchiveTestsRoot>
    <TestArchiveTestsDir>$(TestArchiveTestsRoot)$(OSPlatformConfig)/</TestArchiveTestsDir>
    <TestArchiveRuntimeRoot>$(TestArchiveRoot)runtime/</TestArchiveRuntimeRoot>

    <PublishTestAsSelfContainedDependsOn>BuildMonoiOSApp</PublishTestAsSelfContainedDependsOn>
    <PublishTestAsSelfContainedAfterTargets>BuildMonoiOSApp</PublishTestAsSelfContainedAfterTargets>
    <BundleTestAppleAppDependsOn>GenerateRunScript</BundleTestAppleAppDependsOn>

    <IsRuntimeTests>true</IsRuntimeTests>
  </PropertyGroup>

  <Import Project="$(RepositoryEngineeringDir)testing\tests.targets"
          Condition="'$(TargetsAppleMobile)' == 'true' and '$(RuntimeFlavor)' == 'mono'" />

  <Target Name="_SetRunScriptOutputDirectory" Condition="'$(TargetsAppleMobile)' == 'true' and '$(RuntimeFlavor)' == 'mono' and '$(IsRuntimeTests)' == 'true'" BeforeTargets="GenerateRunScript">
    <PropertyGroup>
      <RunScriptOutputDirectory>$(ArtifactsDir)/tests/coreclr/obj/$(TargetOS).$(Platform).$(Configuration)/Managed/build/iOSApps/$(TestProjectName)/AppBundle</RunScriptOutputDirectory>
    </PropertyGroup>
  </Target>

  <!-- Default priority building values. -->
  <PropertyGroup>
    <DisableProjectBuild Condition="'$(IsMergedTestRunnerAssembly)' == 'true' and $(BuildAsStandalone)">true</DisableProjectBuild>
    <OutputType Condition="('$(IsMergedTestRunnerAssembly)' == 'true' and !$(BuildAsStandalone)) or ('$(RequiresProcessIsolation)' == 'true' and '$(CLRTestKind)' != 'SharedLibrary')">Exe</OutputType>

    <CLRTestKind Condition="'$(CLRTestKind)' == '' and '$(OutputType)' == 'Exe'">BuildAndRun</CLRTestKind>
    <CLRTestKind Condition="'$(CLRTestKind)' == ''">SharedLibrary</CLRTestKind>
    <CLRTestPriority Condition="'$(CLRTestPriority)' == ''">0</CLRTestPriority>

    <!-- Merged test runner assemblies might not have any non-generated sources, and that's okay -->
    <NoWarn Condition="'$(IsMergedTestRunnerAssembly)' == 'true'">$(NoWarn);CS2008</NoWarn>
  </PropertyGroup>

  <!-- All CLRTests need to be of a certain "kind". These kinds are enumerated below.
  By default all tests are BuildAndRun. This means that the build system will Build them
  and construct a run-batch-script for them. -->
  <Choose>
    <When Condition=" '$(CLRTestKind)'=='SharedLibrary'">
      <PropertyGroup>
        <_CLRTestCompilesSource>true</_CLRTestCompilesSource>
        <_CLRTestNeedsToRun>false</_CLRTestNeedsToRun>
        <GenerateRunScript>false</GenerateRunScript>
        <_CLRTestBuildsExecutable>false</_CLRTestBuildsExecutable>
      </PropertyGroup>
    </When>
    <When Condition=" '$(CLRTestKind)'=='BuildAndRun' ">
      <PropertyGroup>
        <GenerateRunScript>true</GenerateRunScript>
        <_CLRTestNeedsToRun>true</_CLRTestNeedsToRun>
        <_CLRTestCompilesSource>true</_CLRTestCompilesSource>
        <_CLRTestBuildsExecutable>true</_CLRTestBuildsExecutable>
      </PropertyGroup>
    </When>
    <When Condition=" '$(CLRTestKind)'=='BuildOnly'">
      <PropertyGroup>
        <_CLRTestNeedsToRun>false</_CLRTestNeedsToRun>
        <GenerateRunScript>false</GenerateRunScript>
        <_CLRTestCompilesSource>true</_CLRTestCompilesSource>
        <_CLRTestBuildsExecutable>true</_CLRTestBuildsExecutable>
      </PropertyGroup>
    </When>
    <When Condition=" '$(CLRTestKind)'=='RunOnly' ">
      <PropertyGroup>
        <GenerateRunScript>true</GenerateRunScript>
        <SkipSigning>true</SkipSigning>
        <_CLRTestBuildsExecutable>false</_CLRTestBuildsExecutable>
        <_CLRTestNeedsToRun>true</_CLRTestNeedsToRun>
        <_CLRTestCompilesSource>false</_CLRTestCompilesSource>
      </PropertyGroup>
    </When>
  </Choose>

  <PropertyGroup>
    <_CLRTestNeedsProjectToRun>false</_CLRTestNeedsProjectToRun>
    <_CLRTestNeedsProjectToRun Condition=" '$(_CLRTestNeedsToRun)' and '!$(_CLRTestBuildsExecutable)' ">true</_CLRTestNeedsProjectToRun>
  </PropertyGroup>

  <PropertyGroup>
    <!-- Since bug in Roslyn for Linux empty DebugType property leads to build failure. See issue Roslyn@20343 -->
    <DebugType Condition=" '$(DebugType)' == '' and '$(RunningOnUnix)' == 'true' ">None</DebugType>
    <TestLibraryProjectPath>$(RepoRoot)\src\tests\Common\CoreCLRTestLibrary\CoreCLRTestLibrary.csproj</TestLibraryProjectPath>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="$(TestLibraryProjectPath)" Condition="'$(IsMergedTestRunnerAssembly)' == 'true'" />
  </ItemGroup>

  <!--
  If it needs ProjectToRun, turn the project into a ProjectReference so it gets built
  -->
  <ItemGroup Condition=" $(_CLRTestNeedsProjectToRun) ">
    <ProjectReference Include="$(CLRTestProjectToRun)">
      <Private>false</Private>
    </ProjectReference>
  </ItemGroup>

  <PropertyGroup Condition="'$(RequiresCodeFlowEnforcement)' == 'true'">
    <CLRTestTargetUnsupported Condition="'$(UseCodeFlowEnforcement)' != 'true'">true</CLRTestTargetUnsupported>
  </PropertyGroup>

  <!-- Determine if this project should be built or not -->
  <PropertyGroup>
    <BuildAllProjects Condition="'$(BuildAllProjects)' == ''">false</BuildAllProjects>
    <_WillCLRTestProjectBuild Condition="'$(_WillCLRTestProjectBuild)' == ''">false</_WillCLRTestProjectBuild>
    <_WillCLRTestProjectBuild Condition="'$(BuildAllProjects)' != 'true'">true</_WillCLRTestProjectBuild>
    <_WillCLRTestProjectBuild Condition="'$(BuildAllProjects)' == 'true' And '$(CLRTestPriority)' &lt;= '$(CLRTestPriorityToBuild)'">true</_WillCLRTestProjectBuild>
    <_WillCLRTestProjectBuild Condition="'$(CLRTestBuildAllTargets)' != 'allTargets' And '$(CLRTestTargetUnsupported)' == 'true'">false</_WillCLRTestProjectBuild>
    <_WillCLRTestProjectBuild Condition="'$(DisableProjectBuild)' == 'true'">false</_WillCLRTestProjectBuild>
    <_WillCLRTestProjectBuild Condition="'$(NativeAotIncompatible)' == 'true' and '$(TestBuildMode)' == 'nativeaot'">false</_WillCLRTestProjectBuild>
    <_WillCLRTestProjectBuild Condition="'$(RuntimeFlavor)' == 'mono' And '$(AlwaysUseCrossgen2)' == 'true'">false</_WillCLRTestProjectBuild>
    <_WillCLRTestProjectBuild Condition="'$(EnableNativeSanitizers)' != '' And '$(AlwaysUseCrossgen2)' == 'true'">false</_WillCLRTestProjectBuild>
  </PropertyGroup>
  <PropertyGroup>
    <_CopyNativeProjectBinaries Condition="'$(__CopyNativeTestBinaries)' != '1'">$(__CopyNativeProjectsAfterCombinedTestBuild)</_CopyNativeProjectBinaries>
    <_CopyNativeProjectBinaries Condition="'$(_WillCLRTestProjectBuild)' != 'true'">false</_CopyNativeProjectBinaries>
    <_CopyNativeProjectBinaries Condition="'$(_CopyNativeProjectBinaries)' == ''">true</_CopyNativeProjectBinaries>
  </PropertyGroup>

  <!-- We enable auto-unification of assembly references after importing the common targets.  Binding redirects are not needed
       for coreclr since it auto-unifies, so the warnings we get without this setting are just noise -->
  <PropertyGroup>
    <AutoUnifyAssemblyReferences>true</AutoUnifyAssemblyReferences>
  </PropertyGroup>

  <!-- Project language -->
  <!-- TODO: This might just be the Language property -->
  <PropertyGroup Condition="'$(ProjectLanguage)' == ''">
    <ProjectLanguage Condition="'$(MSBuildProjectExtension)' == '.ilproj' OR '$(Language)' == 'IL'">IL</ProjectLanguage>
    <ProjectLanguage Condition="'$(MSBuildProjectExtension)' == '.csproj' OR '$(Language)' == 'C#' OR '$(ProjectLanguage)'==''">CSharp</ProjectLanguage>

    <SkipImportILTargets Condition="'$(CLRTestPriority)' &gt; '$(CLRTestPriorityToBuild)'">true</SkipImportILTargets>
    <SkipImportILTargets Condition="'$(CLRTestBuildAllTargets)' != '' And '$(CLRTestNeedTarget)' != '$(CLRTestBuildAllTargets)'">true</SkipImportILTargets>
  </PropertyGroup>

  <!-- If a test in a merged test directory (e.g., under JIT\Directed where Directed_1.csproj and siblings -->
  <!-- represent the groups) has OutputType==Exe set, then it will end up being skipped because the merged -->
  <!-- groups are supposed to cover all of the tests. The merged groups themselves should be Exes, as      -->
  <!-- should any test marked RequiresProcessIsolation or BuildAsStandalone. -->
  <Target Name="CheckForTestOutsideOfGroup" BeforeTargets="Build">
    <Error Condition="'$(InMergedTestDirectory)' == 'true'
      and '$(OutputType)' == 'Exe'
      and '$(_CLRTestNeedsToRun)' == 'true'
      and '$(RequiresProcessIsolation)' != 'true'
      and '$(BuildAsStandalone)' != 'true'
      and '$(IsMergedTestRunnerAssembly)' != 'true'"
      Text="Tests in merged test directories should not set OutputType to Exe unless they are RequiresProcessIsolation, BuildAsStandalone, or IsMergedTestRunnerAssembly." />
  </Target>

  <Target Name="CopyNativeProjectBinaries" Condition="'$(_CopyNativeProjectBinaries)' == 'true'">
    <ItemGroup Condition="'$(UseVisualStudioNativeBinariesLayout)' == 'true'">
      <NativeProjectBinaries Include="$(NativeProjectOutputFolder)\*.*" />
    </ItemGroup>
    <ItemGroup Condition="'$(UseVisualStudioNativeBinariesLayout)' != 'true'">
      <!-- ############################################################### -->
      <!-- The following is required because the single configuration      -->
      <!-- generators, unlike multi-configuration generators,              -->
      <!-- do not place the binaries built into a separate                 -->
      <!-- Debug/Checked/Release directory. Therefore we must filter       -->
      <!-- the folder to only include dynamic libraries, static libraries  -->
      <!--  and executables.                                               -->
      <!--                                                                 -->
      <!-- Please take care when modifying the following lines of code.    -->
      <!-- ############################################################### -->

      <!-- Include everything and then filter. -->
      <NativeProjectBinariesMatched Include="$(NativeProjectOutputFolder)\**\*.*" />

      <!-- Filter executables on unix -->
      <NativeProjectBinariesExeFilter Condition="'%(Extension)' == ''" Include="@(NativeProjectBinariesMatched)" />

      <!-- Filter executables on Windows -->
      <NativeProjectBinariesExeFilter Condition="'%(Extension)' == '.exe'" Include="@(NativeProjectBinariesMatched)" />

      <!-- Filter manifest/data files on Windows -->
      <NativeProjectBinariesManifestFilter Condition="'%(Extension)' == '.manifest'" Include="@(NativeProjectBinariesMatched)" />
      <NativeProjectBinariesManifestFilter Condition="'%(Extension)' == '.tlb'" Include="@(NativeProjectBinariesMatched)" />

      <!-- Filter out the *Make* files -->
      <NativeProjectBinariesExeFilterRemovedMakeFile Condition="'%(FileName)' != 'Makefile'" Include="@(NativeProjectBinariesExeFilter)" />

      <!-- Filter .dylib files for OSX -->
      <NativeProjectBinariesDyLibFilter Condition="'%(Extension)' == '.dylib'" Include="@(NativeProjectBinariesMatched)" />

      <!-- Filter .so files for Linux -->
      <NativeProjectBinariesDyLibFilter Condition="'%(Extension)' == '.so'" Include="@(NativeProjectBinariesMatched)" />

      <!-- Filter static lib files for Unix -->
      <NativeProjectBinariesStaticLibFilter Condition="'%(Extension)' == '.a'" Include="@(NativeProjectBinariesMatched)" />

      <!-- Filter dynamic lib files for Windows -->
      <NativeProjectBinariesDyLibFilter Condition="'%(Extension)' == '.dll'" Include="@(NativeProjectBinariesMatched)" />

      <!-- Filter symbol files for Windows -->
      <NativeProjectsBinariesSymbolsFilter Condition="'%(Extension)' == '.pdb'" Include="@(NativeProjectBinariesMatched)" />

      <!-- Filter static lib files for Windows -->
      <NativeProjectBinariesStaticLibFilter Condition="'%(Extension)' == '.lib'" Include="@(NativeProjectBinariesMatched)" />

      <!-- Filter .dex and .jar files for Android -->
      <NativeProjectBinariesJavaLibFilter Condition="'%(Extension)' == '.dex'" Include="@(NativeProjectBinariesMatched)" />
      <NativeProjectBinariesJavaLibFilter Condition="'%(Extension)' == '.jar'" Include="@(NativeProjectBinariesMatched)" />

      <!-- Merge the filtered lists -->
      <NativeProjectBinaries Include="@(NativeProjectBinariesExeFilterRemovedMakeFile)" />
      <NativeProjectBinaries Include="@(NativeProjectBinariesDyLibFilter)" />
      <NativeProjectBinaries Include="@(NativeProjectBinariesStaticLibFilter)" />
      <NativeProjectBinaries Include="@(NativeProjectsBinariesSymbolsFilter)" />
      <NativeProjectBinaries Include="@(NativeProjectBinariesManifestFilter)" />
      <NativeProjectBinaries Include="@(NativeProjectBinariesJavaLibFilter)" />
    </ItemGroup>

     <!-- There are currently no native project binaries on wasm or Android -->
     <Error  Text="The native project files are missing in $(NativeProjectOutputFolder) please run build from the root of the repo at least once"
             Condition="'@(NativeProjectBinaries)' == '' And '$(TargetOS)' != 'browser' And '$(TargetsMobile)' != 'true'"/>

     <Copy
        SourceFiles="@(NativeProjectBinaries)"
        DestinationFiles="@(NativeProjectBinaries -> '$(OutDir)%(Filename)%(Extension)')"
        SkipUnchangedFiles="$(SkipCopyUnchangedFiles)"
        OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
        Retries="$(CopyRetryCount)"
        RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)"
        UseHardlinksIfPossible="$(CreateHardLinksForCopyFilesToOutputDirectoryIfPossible)">
        <Output TaskParameter="DestinationFiles" ItemName="FileWrites" />
     </Copy>
  </Target>

  <Target Name="ResolveCMakeNativeProjectReference"
          Condition="'@(CMakeProjectReference)' != ''"
          BeforeTargets="ConsolidateNativeProjectReference;BeforeResolveReferences;BeforeClean" >
     <ItemGroup>
        <NativeProjectReference Include="%(CMakeProjectReference.Identity)" Condition="$([System.String]::Copy(%(CMakeProjectReference.FileName)).ToUpper()) == 'CMAKELISTS'" />
        <NativeProjectReferenceNormalized Include="@(NativeProjectReference -> '%(FullPath)')" />
     </ItemGroup>
  </Target>

  <Target Name="ConsolidateNativeProjectReference"
          Condition="'$(_CopyNativeProjectBinaries)' == 'true'"
          BeforeTargets="Build" >
     <ItemGroup Condition="'@(NativeProjectReferenceNormalized)' != ''">
        <NativeProjectOutputFoldersToCopy Include="$([System.String]::Copy('%(NativeProjectReferenceNormalized.RelativeDir)').Replace($(TestSourceDir),$(__NativeTestIntermediatesDir)\))" Condition="'$(UseVisualStudioNativeBinariesLayout)' != 'true'" />
        <NativeProjectOutputFoldersToCopy Include="$([System.String]::Copy('%(NativeProjectReferenceNormalized.RelativeDir)').Replace($(TestSourceDir),$(__NativeTestIntermediatesDir)\))$(Configuration)\" Condition="'$(UseVisualStudioNativeBinariesLayout)' == 'true'" />
     </ItemGroup>

    <Message Text= "Full native project references are :%(NativeProjectReferenceNormalized.Identity)" />
    <Message Text= "Native binaries will be copied from :%(NativeProjectOutputFoldersToCopy.Identity)" />

    <MSBuild Projects="$(MSBuildProjectFile)" Targets="CopyNativeProjectBinaries" Properties="NativeProjectOutputFolder=%(NativeProjectOutputFoldersToCopy.Identity)" Condition="'@(NativeProjectReference)' != ''" />

    <MSBuild Projects="@(ProjectReference)"
        Targets="CopyAllNativeProjectReferenceBinaries"
        Condition="'$(IsMergedTestRunnerAssembly)' == 'true'"
        SkipNonexistentTargets="true"
        BuildInParallel="true" />
  </Target>

  <Target Name="CopyAllNativeProjectReferenceBinaries"
          DependsOnTargets="ResolveCMakeNativeProjectReference;ConsolidateNativeProjectReference"
          BeforeTargets="Build">

    <ItemGroup Condition="'$(IsMergedTestRunnerAssembly)' == 'true'">
      <OutOfProcessTestMarkers Include="$(OutDir)/../**/*.OutOfProcessTest" />
      <OutOfProcessTestFolders Include="$([MSBuild]::NormalizePath('$([System.IO.Path]::GetDirectoryName('%(OutOfProcessTestMarkers.FullPath)'))'))" Condition="'@(OutOfProcessTestMarkers)' != ''" />
      <MergedWrapperReferenceFolders Include="@(ProjectReference->'$([MSBuild]::NormalizePath('$([System.IO.Path]::GetFullPath('%(ProjectReference.Identity)/..', '$(OutDir)/..'))/%(ProjectReference.FileName)'))')" />
      <!-- Don't copy out-of-process test components to the merged wrapper output folder -->
      <MergedWrapperReferenceFolders Remove="@(OutOfProcessTestFolders)" />
      <!-- For merged project wrappers, include native libraries in all project references -->
      <MergedWrapperReferenceFiles Include="%(MergedWrapperReferenceFolders.Identity)/*$(LibSuffix)" Condition="'@(MergedWrapperReferenceFolders)' != ''" />
    </ItemGroup>
    <Copy SourceFiles="@(MergedWrapperReferenceFiles)"
        DestinationFiles="@(MergedWrapperReferenceFiles->'$(OutDir)/%(FileName)%(Extension)')"
        SkipUnchangedFiles="true"
        Condition="'@(MergedWrapperReferenceFiles)' != ''"
        />
  </Target>

  <!-- Build shell or command scripts whenever we copy native binaries -->
  <Import Project="$(MSBuildThisFileDirectory)Common\CLRTest.Execute.targets" />
  <Target Name="CreateExecuteScript"
          BeforeTargets="Build;CopyAllNativeProjectReferenceBinaries"
          Condition="'$(CLRTestBuildAllTargets)' != 'allTargets' And '$(GenerateRunScript)' != 'false' And ('$(_WillCLRTestProjectBuild)' == 'true')"
          DependsOnTargets="GenerateExecutionScriptsInternal" />

  <Target Name="UpdateReferenceItems"
          BeforeTargets="BeforeResolveReferences"
  >
   <MSBuild Projects="$(MSBuildProjectFullPath)"
            Targets="GetLiveRefAssemblies">
    <Output TaskParameter="TargetOutputs" ItemName="Reference" />
   </MSBuild>

    <ItemGroup>
      <Reference Include="$(TargetingPackPath)/*.dll" >
        <Private>false</Private>
      </Reference>
    </ItemGroup>

  </Target>

  <Target Name="GetLiveRefAssemblies" Returns="@(LibrariesRefAssembliesDlls)"
          DependsOnTargets="ResolveLibrariesRefAssembliesFromLocalBuild">
    <ItemGroup>
      <LibrariesRefAssembliesDlls Include="@(LibrariesRefAssemblies)" Condition="'%(Extension)' == '.dll'" Private="false" />
    </ItemGroup>
  </Target>

  <Target Name="ConvertCountOfStressMarkersToListPhase1" BeforeTargets="ConvertCountOfStressMarkersToListPhase1">
    <PropertyGroup>
      <SequenceOfSemicolons>$([System.String]::new(';',10))</SequenceOfSemicolons>
    </PropertyGroup>
  </Target>

  <Target Name="GenerateMarkerFiles" BeforeTargets="AssignTargetPaths">
    <PropertyGroup Condition="'$(NumberOfStripesToUseInStress)' == '' and '$(IsMergedTestRunnerAssembly)' == 'true'">
      <NumberOfStripesToUseInStress>1</NumberOfStripesToUseInStress> <!-- Set a custom number of stripes in stress to allow very large merged groups to function in the presence of GCStress -->
    </PropertyGroup>

    <!-- Generate a set of stress marker files to be used in stress scenarios in CI runs -->
    <ItemGroup Condition="'$(NumberOfStripesToUseInStress)' != '' and '$(IsMergedTestRunnerAssembly)' == 'true'">
      <SequenceOfIntegers Include="0"/>
      <SequenceOfIntegers Include="1"/>
      <SequenceOfIntegers Include="2"/>
      <SequenceOfIntegers Include="3"/>
      <SequenceOfIntegers Include="4"/>
      <SequenceOfIntegers Include="5"/>
      <SequenceOfIntegers Include="6"/>
      <SequenceOfIntegers Include="7"/>
      <SequenceOfIntegers Include="8"/>
      <SequenceOfIntegers Include="9"/>
      <SequenceOfIntegers Include="10"/>
      <SequenceOfIntegers Include="11"/>
      <SequenceOfIntegers Include="12"/>
      <SequenceOfIntegers Include="13"/>
      <SequenceOfIntegers Include="14"/>
      <SequenceOfIntegers Include="15"/>
      <SequenceOfIntegers Include="16"/>
      <SequenceOfIntegers Include="17"/>
      <SequenceOfIntegers Include="18"/>
      <SequenceOfIntegers Include="19"/>
      <SequenceOfIntegers Include="20"/>
      <SequenceOfIntegers Include="21"/>
      <SequenceOfIntegers Include="22"/>
      <SequenceOfIntegers Include="23"/>
      <SequenceOfIntegers Include="24"/>
      <SequenceOfIntegers Include="25"/>
      <SequenceOfIntegers Include="26"/>
      <SequenceOfIntegers Include="27"/>
      <SequenceOfIntegers Include="28"/>
      <SequenceOfIntegers Include="29"/>
      <SequenceOfIntegers Include="20"/>
      <SequenceOfIntegers Include="31"/>
      <SequenceOfIntegers Include="32"/>
      <SequenceOfIntegers Include="33"/>
      <SequenceOfIntegers Include="34"/>
      <SequenceOfIntegers Include="35"/>
      <SequenceOfIntegers Include="36"/>
      <SequenceOfIntegers Include="37"/>
      <SequenceOfIntegers Include="38"/>
      <SequenceOfIntegers Include="39"/>
      <SequenceOfIntegers Include="40"/>
      <SequenceOfIntegers Include="41"/>
      <SequenceOfIntegers Include="42"/>
      <SequenceOfIntegers Include="43"/>
      <SequenceOfIntegers Include="44"/>
      <SequenceOfIntegers Include="45"/>
      <SequenceOfIntegers Include="46"/>
      <SequenceOfIntegers Include="47"/>
      <SequenceOfIntegers Include="48"/>
      <SequenceOfIntegers Include="49"/>
      <SequenceOfIntegers Include="50"/>
      <SequenceOfIntegers Include="51"/>
      <SequenceOfIntegers Include="52"/>
      <SequenceOfIntegers Include="53"/>
      <SequenceOfIntegers Include="54"/>
      <SequenceOfIntegers Include="55"/>
      <SequenceOfIntegers Include="56"/>
      <SequenceOfIntegers Include="57"/>
      <SequenceOfIntegers Include="58"/>
      <SequenceOfIntegers Include="59"/>
      <SequenceOfIntegers Include="60"/>
      <SequenceOfIntegers Include="61"/>
      <SequenceOfIntegers Include="62"/>
      <SequenceOfIntegers Include="63"/>
      <SequenceOfIntegers Include="64"/>
      <SequenceOfIntegers Include="65"/>
      <SequenceOfIntegers Include="66"/>
      <SequenceOfIntegers Include="67"/>
      <SequenceOfIntegers Include="68"/>
      <SequenceOfIntegers Include="69"/>
      <SequenceOfIntegers Include="70"/>
      <SequenceOfIntegers Include="71"/>
      <SequenceOfIntegers Include="72"/>
      <SequenceOfIntegers Include="73"/>
      <SequenceOfIntegers Include="74"/>
      <SequenceOfIntegers Include="75"/>
      <SequenceOfIntegers Include="76"/>
      <SequenceOfIntegers Include="77"/>
      <SequenceOfIntegers Include="78"/>
      <SequenceOfIntegers Include="79"/>
      <SequenceOfIntegers Include="80"/>
      <SequenceOfIntegers Include="81"/>
      <SequenceOfIntegers Include="82"/>
      <SequenceOfIntegers Include="83"/>
      <SequenceOfIntegers Include="84"/>
      <SequenceOfIntegers Include="85"/>
      <SequenceOfIntegers Include="86"/>
      <SequenceOfIntegers Include="87"/>
      <SequenceOfIntegers Include="88"/>
      <SequenceOfIntegers Include="89"/>
      <SequenceOfIntegers Include="90"/>
      <SequenceOfIntegers Include="91"/>
      <SequenceOfIntegers Include="92"/>
      <SequenceOfIntegers Include="93"/>
      <SequenceOfIntegers Include="94"/>
      <SequenceOfIntegers Include="95"/>
      <SequenceOfIntegers Include="96"/>
      <SequenceOfIntegers Include="97"/>
      <SequenceOfIntegers Include="98"/>
      <SequenceOfIntegers Include="99"/>

      <MarkerFileIntegerSequence Include="@(SequenceOfIntegers)" Condition="%(Identity)&lt;$(NumberOfStripesToUseInStress)" />
      <MarkerFile Include="@(MarkerFileIntegerSequence->'$(IntermediateOutputPath)\$(MSBuildProjectName).MergedTestAssembly.%(Identity).$(NumberOfStripesToUseInStress).MergedTestAssemblyForStress')">
        <Type>MergedStressTestAssembly</Type>
      </MarkerFile>
    </ItemGroup>
    <Error Condition="'$(NumberOfStripesToUseInStress)' != '' and $(NumberOfStripesToUseInStress)&gt;99" Text="Attempt to split into too many stripes. Either reduce stripe count, or add more entries to SequenceOfIntegers" />

    <ItemGroup>
      <Content Include="$(AssemblyName).reflect.xml" Condition="Exists('$(AssemblyName).reflect.xml')" CopyToOutputDirectory="PreserveNewest" />
      <MarkerFile Include="$(IntermediateOutputPath)\$(MSBuildProjectName).MergedTestAssembly" Condition="'$(IsMergedTestRunnerAssembly)' == 'true'">
        <Type>MergedTestAssembly</Type>
      </MarkerFile>
      <MarkerFile Include="$(IntermediateOutputPath)\$(AssemblyName).NoMonoAot" Condition="'$(MonoAotIncompatible)' == 'true'">
        <Type>NoMonoAot</Type>
      </MarkerFile>
      <Content Include="@(MarkerFile)" CopyToOutputDirectory="PreserveNewest" />
    </ItemGroup>

     <Copy SourceFiles="$(AssemblyName).reflect.xml"
           DestinationFolder="$(OutputPath)"
       Condition="Exists('$(AssemblyName).reflect.xml')"/>

    <WriteLinesToFile
        Condition="'@(MarkerFile)' != ''"
        File="%(Identity)"
        Lines="%(Type)"
        Overwrite="true"
        WriteOnlyWhenDifferent="true" />

    <!-- We don't want the out-of-process test marker file to be included in referencing projects, so we don't include it as content. -->
    <WriteLinesToFile
        Condition="'$(RequiresProcessIsolation)' == 'true' and '$(BuildAsStandalone)' != 'true'"
        File="$(OutputPath)\$(AssemblyName).OutOfProcessTest"
        Lines="OutOfProcessTest"
        Overwrite="true"
        WriteOnlyWhenDifferent="true" />
  </Target>

  <PropertyGroup>
    <ProjectAssetsFile>$(BaseOutputPath)\packages\Common\test_dependencies\test_dependencies\project.assets.json</ProjectAssetsFile>
  </PropertyGroup>
  <Import Project="$(BaseOutputPath)\packages\Common\test_dependencies\test_dependencies\test_dependencies.*.targets" />


  <PropertyGroup>
    <DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
  </PropertyGroup>

  <PropertyGroup>
    <IncludeOOBLibraries>true</IncludeOOBLibraries>
  </PropertyGroup>

  <ItemGroup>
    <KnownFrameworkReference Remove="Microsoft.AspNetCore.App" />
    <KnownFrameworkReference Remove="Microsoft.WindowsDesktop.App" />
  </ItemGroup>

  <Target Name="GetProjectsWithDisabledBuild" Returns="@(ProjectWithDisabledBuild)">
    <ItemGroup Condition="'$(_WillCLRTestProjectBuild)' != 'true'">
      <ProjectWithDisabledBuild Include="$(MSBuildProjectFullPath)" />
    </ItemGroup>
  </Target>

  <Target Name="GetRequiresProcessIsolation" Returns="@(ProjectRequiringProcessIsolation)">
    <ItemGroup Condition="'$(RequiresProcessIsolation)' == 'true'">
      <ProjectRequiringProcessIsolation Include="$(MSBuildProjectFullPath)" />
    </ItemGroup>
  </Target>

  <Target Name="DiscoverProcessIsolatedTestProjectReferences" BeforeTargets="AssignProjectConfiguration" Condition="'$(IsMergedTestRunnerAssembly)' == 'true'">
    <MSBuild Projects="@(ProjectReference)" Targets="GetRequiresProcessIsolation" SkipNonexistentTargets="true">
      <Output TaskParameter="TargetOutputs" ItemName="ReferencedProjectRequiringProcessIsolation" />
    </MSBuild>

    <ItemGroup>
      <ProjectReference Remove="@(ReferencedProjectRequiringProcessIsolation->'%(OriginalItemSpec)')" />
      <ProjectReference Include="@(ReferencedProjectRequiringProcessIsolation->'%(OriginalItemSpec)')" OutputItemType="OutOfProcessTests" BuildReference="true" ReferenceOutputAssembly="false" Private="False" />
    </ItemGroup>
  </Target>

  <PropertyGroup Condition="'$(Language)' == 'C#' and '$(_CLRTestNeedsToRun)' == 'true' and ('$(BuildAsStandalone)' == 'true' or '$(RequiresProcessIsolation)' == 'true' or '$(InMergedTestDirectory)' == 'true' or '$(IsMergedTestRunnerAssembly)' == 'true')">
    <ReferenceXUnitWrapperGenerator Condition="'$(ReferenceXUnitWrapperGenerator)' == ''">true</ReferenceXUnitWrapperGenerator>
  </PropertyGroup>

  <ItemGroup Condition="'$(ReferenceXUnitWrapperGenerator)' == 'true'">
    <ProjectReference Include="$(RepoRoot)/src/tests/Common/XUnitWrapperGenerator/XUnitWrapperGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
  </ItemGroup>

  <ItemGroup Condition="'$(IsMergedTestRunnerAssembly)' == 'true'">
    <ProjectReference Include="$(RepoRoot)/src/tests/Common/XUnitWrapperLibrary/XUnitWrapperLibrary.csproj" />
  </ItemGroup>

  <Import Project="$(RepoRoot)/src/tests/Common/XUnitWrapperGenerator/XUnitWrapperGenerator.props" />
  <Import Project="$(RepoRoot)eng/liveBuilds.targets" />
  <Import Project="$(MSBuildProjectFullPath).targets" Condition="Exists('$(MSBuildProjectFullPath).targets')"/>
  <Import Project="$(RepoRoot)/src/tests/Common/mergedrunner.targets" Condition="'$(IsMergedTestRunnerAssembly)' == 'true'" />

  <Target Name="GetBinPlaceTargetFramework" />

  <Import Project="$(RepoRoot)src\coreclr\clr.featuredefines.props" />

  <!-- if we have determined that there is nothing to build, overwrite the build targets so that nothing happens -->
  <Import Project="$(MSBuildThisFileDirectory)Common\nobuild.targets" Condition="'$(_WillCLRTestProjectBuild)' == 'false'" />

  <!-- RunOnly projects have a special build for dependent projects -->
  <Import Project="$(MSBuildThisFileDirectory)Common\runonly.targets" Condition="'$(CLRTestKind)' == 'RunOnly'" />

  <PropertyGroup Condition="'$(TestBuildMode)' == 'nativeaot'">
    <!-- NativeAOT compiled output is placed into a 'native' subdirectory: we need to tweak
         rpath so that the test can load its native library dependencies if there's any -->
    <IlcRPath Condition="'$(TargetOS)' == 'osx' or '$(TargetsAppleMobile)' == 'true'">@executable_path/..</IlcRPath>
    <IlcRPath Condition="'$(IlcRPath)' == ''">$ORIGIN/..</IlcRPath>

    <!-- Works around "Error: Native compilation can run on x64 and arm64 hosts only" -->
    <DisableUnsupportedError>true</DisableUnsupportedError>

    <!-- IL projects often have mismatches assembly names vs file names and that breaks Win32 resource generation option -->
    <IlcGenerateWin32Resources Condition="'$(Language)' == 'IL'">false</IlcGenerateWin32Resources>

    <!-- The default TrimMode in the SDK is full. But trimming most of the tests would just make them fail,
         so the default for the test tree is partial. -->
    <TrimMode Condition="'$(EnableAggressiveTrimming)' != 'true'">partial</TrimMode>

    <IlcTreatWarningsAsErrors>false</IlcTreatWarningsAsErrors>

    <IlcToolsPath>$(CoreCLRILCompilerDir)</IlcToolsPath>
    <IlcToolsPath Condition="'$(TargetArchitecture)' != '$(BuildArchitecture)' or '$(TargetOS)' != '$(HostOS)' or '$(EnableNativeSanitizers)' != ''">$(CoreCLRCrossILCompilerDir)</IlcToolsPath>
    <IlcBuildTasksPath>$(CoreCLRILCompilerDir)netstandard/ILCompiler.Build.Tasks.dll</IlcBuildTasksPath>
    <IlcSdkPath>$(CoreCLRAotSdkDir)</IlcSdkPath>
    <IlcFrameworkPath>$(MicrosoftNetCoreAppRuntimePackRidLibTfmDir)</IlcFrameworkPath>
    <IlcFrameworkNativePath>$(MicrosoftNetCoreAppRuntimePackNativeDir)</IlcFrameworkNativePath>
    <RuntimeIdentifier>$(OutputRID)</RuntimeIdentifier>

    <SysRoot Condition="'$(CrossBuild)' == 'true' and '$(HostOS)' != 'windows'">$(ROOTFS_DIR)</SysRoot>
    <BuildNativeAotFrameworkObjects Condition="'$(IlcMultiModule)' == 'true'">true</BuildNativeAotFrameworkObjects>
    <DisableFrameworkLibGeneration Condition="'$(BuildNativeAotFrameworkObjects)' == 'true'">true</DisableFrameworkLibGeneration>
    <FrameworkLibPath Condition="'$(BuildNativeAotFrameworkObjects)' == 'true'">$(IlcSdkPath)</FrameworkLibPath>

    <!-- Forced by ILLink targets -->
    <SelfContained>true</SelfContained>
    <HasRuntimeOutput>false</HasRuntimeOutput>
    <_UsingDefaultForHasRuntimeOutput>false</_UsingDefaultForHasRuntimeOutput>
  </PropertyGroup>

  <ItemGroup Condition="'$(TestBuildMode)' == 'nativeaot'">
    <CustomLinkerArg Condition="'$(CrossBuild)' == 'true' and '$(_hostArchitecture)' == '$(_targetArchitecture)' and '$(_hostOS)' != 'windows'" Include="--gcc-toolchain=$(ROOTFS_DIR)/usr" />
    <IlcReference Include="$(TargetingPackPath)/*.dll" />

    <!-- xunit calls MakeGenericType to check if something is IEquatable -->
    <IlcArg Condition="'$(EagerlyValidateTypeConstruction)' != 'false'" Include="--feature:System.Reflection.IsTypeConstructionEagerlyValidated=false" />

    <!-- Bump the generic cycle tolerance. There's at least one test with a cycle that is reachable at runtime to depth 6 -->
    <IlcArg Include="--maxgenericcycle:7" />

    <!-- We set TrimMode to partial so that we don't trim parts of the tests,
         but don't make this apply to xunit cruft -->
    <IlcArg Include="--trim:Microsoft.DotNet.XUnitExtensions" />
    <IlcArg Include="--trim:xunit.abstractions" />
    <IlcArg Include="--trim:xunit.assert" />
    <IlcArg Include="--trim:xunit.console" />
    <IlcArg Include="--trim:xunit.core" />
    <IlcArg Include="--trim:xunit.execution.dotnet" />
    <IlcArg Include="--trim:xunit.abstractions" />
  </ItemGroup>

  <Import Project="$(RepositoryEngineeringDir)nativeSanitizers.targets" Condition="'$(TestBuildMode)' == 'nativeaot'" />

  <Import Project="$(CoreCLRBuildIntegrationDir)Microsoft.DotNet.ILCompiler.SingleEntry.targets" Condition="'$(TestBuildMode)' == 'nativeaot'" />
  <Import Project="$(RepoRoot)eng/liveILLink.targets" />

  <ItemGroup Condition="'$(TestBuildMode)' == 'nativeaot'">
    <Content Include="@(SanitizerRuntimeToCopy->'$(CoreCLRArtifactsPath)/%(Identity)')" CopyToOutputDirectory="PreserveNewest" />
  </ItemGroup>

  <Target Name="BuildNativeAot"
          DependsOnTargets="Build;LinkNativeIfBuildAndRun" />

  <Target Name="LinkNativeIfBuildAndRun"
          Condition="'$(_WillCLRTestProjectBuild)' == 'true' and '$(CLRTestKind)' == 'BuildAndRun'"
          DependsOnTargets="ComputeResolvedFilesToPublishList;LinkNative" />

  <Target Name="LocateNativeCompiler"
          Condition="'$(TestBuildMode)' == 'nativeaot' and '$(HostOS)' != 'windows'"
          BeforeTargets="SetupOSSpecificProps">
    <PropertyGroup>
      <CppCompilerAndLinker Condition="'$(CppCompilerAndLinker)' == ''">clang</CppCompilerAndLinker>
    </PropertyGroup>

    <Exec Command="sh -c 'build_arch=&quot;$(TargetArchitecture)&quot; compiler=&quot;$(CppCompilerAndLinker)&quot; . &quot;$(RepositoryEngineeringDir)/common/native/init-compiler.sh&quot; &amp;&amp; echo &quot;$CC;$LDFLAGS&quot;' 2>/dev/null"
          EchoOff="true"
          ConsoleToMsBuild="true"
          StandardOutputImportance="Low">
      <Output TaskParameter="ConsoleOutput" PropertyName="_CC_LDFLAGS" />
    </Exec>

    <PropertyGroup>
      <CppLinker>$(_CC_LDFLAGS.SubString(0, $(_CC_LDFLAGS.IndexOf(';'))))</CppLinker>
      <_LDFLAGS>$(_CC_LDFLAGS.SubString($([MSBuild]::Add($(_CC_LDFLAGS.IndexOf(';')), 1))))</_LDFLAGS>
      <LinkerFlavor Condition="$(_LDFLAGS.Contains('lld'))">lld</LinkerFlavor>
    </PropertyGroup>
  </Target>

</Project>
